{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Cp 2 Financial Data Structures\n",
    "\n",
    "- How to work with unstructured financial data?\n",
    "\n",
    "\n",
    "### the four essential types of Financial data\n",
    "\n",
    "- fundamental data  ex) assets, liabilities, sales, cost/earnings, macro variables  \n",
    "- Market data ex) volatility, volume...   \n",
    "- Analytics ex) news sentiment, earning expectations..  \n",
    "- Alternative data ex) google searches,metadata    \n",
    "\n",
    "## 2.3.1.2~4 Bars \n",
    "\n",
    "data representation that contains the most aseic info about price movements of a financial assets.\n",
    "\n",
    "\n",
    "## Standard bars\n",
    "\n",
    "- time bars : obtained by sampling info at fixed time intervals: should be avoided(since it is different from the real market)\n",
    "time bars oversample inf during low-activity periods and undersample info during high-activity periods.\n",
    "- tick bars\n",
    "- volume bars: sampling every time a pre-defined amount of the security's units(shars, futures contracts,etc.) have been exchanged.\n",
    "- dollar bars : formed by sampling an observation every time a pre-defined market value is exchanged.\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "import matplotlib.dates as mdates\n",
    "from datetime import datetime\n",
    "import seaborn as sns\n",
    "import time\n",
    "import scipy.stats as stats\n",
    "import math\n",
    "from tqdm import tqdm_notebook\n",
    "import sys\n",
    "from termcolor import colored, cprint\n",
    "\n",
    "import statsmodels.api\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = pd.read_csv('C:/Python/data/test.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>date_time</th>\n",
       "      <th>price</th>\n",
       "      <th>volume</th>\n",
       "      <th>buy</th>\n",
       "      <th>sell</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2018-11-21 09:00:00</td>\n",
       "      <td>266.200012</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2018-11-21 09:00:00</td>\n",
       "      <td>266.200012</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2018-11-21 09:00:00</td>\n",
       "      <td>266.250000</td>\n",
       "      <td>21.0</td>\n",
       "      <td>21.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2018-11-21 09:00:00</td>\n",
       "      <td>266.299988</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2018-11-21 09:00:00</td>\n",
       "      <td>266.350006</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             date_time       price  volume   buy  sell\n",
       "0  2018-11-21 09:00:00  266.200012     1.0   0.0   1.0\n",
       "1  2018-11-21 09:00:00  266.200012     1.0   0.0   1.0\n",
       "2  2018-11-21 09:00:00  266.250000    21.0  21.0   0.0\n",
       "3  2018-11-21 09:00:00  266.299988     1.0   1.0   0.0\n",
       "4  2018-11-21 09:00:00  266.350006     2.0   2.0   0.0"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.head()\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Time bars\n",
    "obtained by sampling info at fixed time intervals: should be avoided\n",
    "- markets do not proceed information at a constant time interval\n",
    "- time-sampled series often exhibit poor statistical properties  \n",
    "time bars oversample info during low-activity periods and undersample info during high-activity periods."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "#그냥 전체를 일정 시간 간격으로 쪼개기\n",
    "\n",
    "# volume weighted avg price\n",
    "def compute_vwap(df):\n",
    "    q = df['volume']\n",
    "    p = df['price']\n",
    "    vwap = np.sum(p*q)/np.sum(q)\n",
    "    df['vwap'] = vwap\n",
    "    return df\n",
    "\n",
    "\n",
    "data['date_time'] =pd.to_datetime(data['date_time']) #change into datetime format\n",
    "def time_bars(data):\n",
    "    data_timeidx = data.set_index('date_time')\n",
    "    data_time_group = data_timeidx.resample('10T').ohlc()\n",
    "    n_time_bars = len(data_time_group)\n",
    "    #data_timeidx.resample('10T').ohlc()\n",
    "    return data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th colspan=\"4\" halign=\"left\">price</th>\n",
       "      <th colspan=\"4\" halign=\"left\">volume</th>\n",
       "      <th colspan=\"4\" halign=\"left\">buy</th>\n",
       "      <th colspan=\"4\" halign=\"left\">sell</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date_time</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2018-11-21 09:00:00</th>\n",
       "      <td>266.200012</td>\n",
       "      <td>266.649994</td>\n",
       "      <td>265.500000</td>\n",
       "      <td>266.350006</td>\n",
       "      <td>1.0</td>\n",
       "      <td>200.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>13.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>200.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>13.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>158.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-11-21 09:10:00</th>\n",
       "      <td>266.350006</td>\n",
       "      <td>266.450012</td>\n",
       "      <td>265.750000</td>\n",
       "      <td>266.350006</td>\n",
       "      <td>3.0</td>\n",
       "      <td>139.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>111.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>139.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-11-21 09:20:00</th>\n",
       "      <td>266.350006</td>\n",
       "      <td>266.450012</td>\n",
       "      <td>265.899994</td>\n",
       "      <td>266.049988</td>\n",
       "      <td>1.0</td>\n",
       "      <td>155.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>155.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-11-21 09:30:00</th>\n",
       "      <td>266.049988</td>\n",
       "      <td>266.200012</td>\n",
       "      <td>265.850006</td>\n",
       "      <td>265.899994</td>\n",
       "      <td>1.0</td>\n",
       "      <td>125.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>80.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>125.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-11-21 09:40:00</th>\n",
       "      <td>265.899994</td>\n",
       "      <td>265.899994</td>\n",
       "      <td>265.500000</td>\n",
       "      <td>265.700012</td>\n",
       "      <td>1.0</td>\n",
       "      <td>114.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>89.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>114.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                          price                                     volume  \\\n",
       "                           open        high         low       close   open   \n",
       "date_time                                                                    \n",
       "2018-11-21 09:00:00  266.200012  266.649994  265.500000  266.350006    1.0   \n",
       "2018-11-21 09:10:00  266.350006  266.450012  265.750000  266.350006    3.0   \n",
       "2018-11-21 09:20:00  266.350006  266.450012  265.899994  266.049988    1.0   \n",
       "2018-11-21 09:30:00  266.049988  266.200012  265.850006  265.899994    1.0   \n",
       "2018-11-21 09:40:00  265.899994  265.899994  265.500000  265.700012    1.0   \n",
       "\n",
       "                                       buy                   sell              \\\n",
       "                      high  low close open   high  low close open   high  low   \n",
       "date_time                                                                       \n",
       "2018-11-21 09:00:00  200.0  1.0  13.0  0.0  200.0  0.0  13.0  1.0  158.0  0.0   \n",
       "2018-11-21 09:10:00  139.0  1.0   1.0  3.0  111.0  0.0   1.0  0.0  139.0  0.0   \n",
       "2018-11-21 09:20:00  155.0  1.0   1.0  1.0  100.0  0.0   0.0  0.0  155.0  0.0   \n",
       "2018-11-21 09:30:00  125.0  1.0   1.0  0.0   80.0  0.0   0.0  1.0  125.0  0.0   \n",
       "2018-11-21 09:40:00  114.0  1.0   1.0  0.0   89.0  0.0   0.0  1.0  114.0  0.0   \n",
       "\n",
       "                           \n",
       "                    close  \n",
       "date_time                  \n",
       "2018-11-21 09:00:00   0.0  \n",
       "2018-11-21 09:10:00   0.0  \n",
       "2018-11-21 09:20:00   1.0  \n",
       "2018-11-21 09:30:00   1.0  \n",
       "2018-11-21 09:40:00   1.0  "
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_timeidx = data.set_index('date_time')\n",
    "data_time_group = data_timeidx.resample('10T').ohlc()\n",
    "n_time_bars = len(data_time_group)\n",
    "data_time_group.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Tick bars\n",
    "\n",
    "\n",
    "sample observations every N trainsactions,aka \"ticks', instead of fixed time buckets.  \n",
    "this allows us to capture more information at times when many trades take place, and vice-versa\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "def tick_bars(data):\n",
    "    ticks = len(data)\n",
    "    num_ticks_per_bar = ticks/n_time_bars\n",
    "    num_ticks_per_bar = round(num_ticks_per_bar, -2)\n",
    "    data_tick_grp = data.reset_index().assign(grpId = lambda row:row.index // num_ticks_per_bar)\n",
    "    data_tick_vwap = data_tick_grp.groupby('grpId').apply(compute_vwap)\n",
    "    data_tick_vwap.set_index('date_time')\n",
    "    \n",
    "    n_tick_idx = len(data_tick_grp)\n",
    "    return data\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>date_time</th>\n",
       "      <th>price</th>\n",
       "      <th>volume</th>\n",
       "      <th>buy</th>\n",
       "      <th>sell</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2018-11-21 09:00:00</td>\n",
       "      <td>266.200012</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2018-11-21 09:00:00</td>\n",
       "      <td>266.200012</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2018-11-21 09:00:00</td>\n",
       "      <td>266.250000</td>\n",
       "      <td>21.0</td>\n",
       "      <td>21.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2018-11-21 09:00:00</td>\n",
       "      <td>266.299988</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2018-11-21 09:00:00</td>\n",
       "      <td>266.350006</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            date_time       price  volume   buy  sell\n",
       "0 2018-11-21 09:00:00  266.200012     1.0   0.0   1.0\n",
       "1 2018-11-21 09:00:00  266.200012     1.0   0.0   1.0\n",
       "2 2018-11-21 09:00:00  266.250000    21.0  21.0   0.0\n",
       "3 2018-11-21 09:00:00  266.299988     1.0   1.0   0.0\n",
       "4 2018-11-21 09:00:00  266.350006     2.0   2.0   0.0"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tick_bars(data).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "ticks = len(data)\n",
    "num_ticks_per_bar = ticks/n_time_bars\n",
    "num_ticks_per_bar = round(num_ticks_per_bar, -2)\n",
    "data_tick_grp = data.reset_index().assign(grpId = lambda row:row.index // num_ticks_per_bar)\n",
    "data_tick_vwap = data_tick_grp.groupby('grpId').apply(compute_vwap)\n",
    "data_tick_vwap.set_index('date_time')\n",
    "    \n",
    "n_tick_idx = len(data_tick_grp)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-0.0069020611673073695"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_drp = data_tick_vwap.drop_duplicates(['grpId'],keep = 'last')\n",
    "data_drp['price'].pct_change().autocorr()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "26284"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(data_drp) #number of tick bars"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Volume bars\n",
    "\n",
    "one shortcoming of tick bars is that not all trades are equal. volume bars circumvent that problem by sampling every time a pre-defined amount of the security's units have been exchanged."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "# sample observations for every N contracts exchanged independent of how many trads took place.\n",
    "def volume_bars(data):\n",
    "    data['CumVol'] =data['volume'].cumsum()\n",
    "    total_vol = data['CumVol'].values[-1] # data in the last row \n",
    "    vol_per_bar = total_vol/n_time_bars\n",
    "    vol_per_bar = round(vol_per_bar , -2)\n",
    "    data_vol_grp = pd.DataFrame(data['CumVol']).assign(grpId = lambda row:row.CumVol // vol_per_bar)\n",
    "    data_vol_grp = pd.merge(data,data_vol_grp)\n",
    "    data_vol_vwap = data_vol_grp.groupby('grpId').apply(compute_vwap)\n",
    "    data_vol_vwap.set_index('date_time')\n",
    "    return  data\n",
    "    #set the relevant group for each row\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "data['CumVol'] =data['volume'].cumsum()\n",
    "total_vol = data['CumVol'].values[-1] # data in the last row \n",
    "vol_per_bar = total_vol/n_time_bars\n",
    "vol_per_bar = round(vol_per_bar , -2)\n",
    "data_vol_grp = pd.DataFrame(data['CumVol']).assign(grpId = lambda row:row.CumVol // vol_per_bar)\n",
    "data_vol_grp = pd.merge(data,data_vol_grp)\n",
    "data_vol_vwap = data_vol_grp.groupby('grpId').apply(compute_vwap) # volume이 변할 때  기준으로  나눠 묶기\n",
    "data_vol_vwap.set_index('date_time')\n",
    "totalvol = total_vol  #to not referenced twice\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>date_time</th>\n",
       "      <th>price</th>\n",
       "      <th>volume</th>\n",
       "      <th>buy</th>\n",
       "      <th>sell</th>\n",
       "      <th>CumVol</th>\n",
       "      <th>grpId</th>\n",
       "      <th>vwap</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2018-11-21 09:00:00</td>\n",
       "      <td>266.200012</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>266.224174</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2018-11-21 09:00:00</td>\n",
       "      <td>266.200012</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>266.224174</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2018-11-21 09:00:00</td>\n",
       "      <td>266.250000</td>\n",
       "      <td>21.0</td>\n",
       "      <td>21.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>23.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>266.224174</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2018-11-21 09:00:00</td>\n",
       "      <td>266.299988</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>24.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>266.224174</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2018-11-21 09:00:00</td>\n",
       "      <td>266.350006</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>26.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>266.224174</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            date_time       price  volume   buy  sell  CumVol  grpId  \\\n",
       "0 2018-11-21 09:00:00  266.200012     1.0   0.0   1.0     1.0    0.0   \n",
       "1 2018-11-21 09:00:00  266.200012     1.0   0.0   1.0     2.0    0.0   \n",
       "2 2018-11-21 09:00:00  266.250000    21.0  21.0   0.0    23.0    0.0   \n",
       "3 2018-11-21 09:00:00  266.299988     1.0   1.0   0.0    24.0    0.0   \n",
       "4 2018-11-21 09:00:00  266.350006     2.0   2.0   0.0    26.0    0.0   \n",
       "\n",
       "         vwap  \n",
       "0  266.224174  \n",
       "1  266.224174  \n",
       "2  266.224174  \n",
       "3  266.224174  \n",
       "4  266.224174  "
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_vol_vwap.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "339"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_drp_v = data_vol_vwap.drop_duplicates(['volume'],keep = 'last')\n",
    "len(data_drp_v) #number of volume bars"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Dollar Bars\n",
    "\n",
    "sampling as a function of dollars(or a currency || market value of your choice) exchanged sholud in theory make the frequency more robust to value fluctuations.\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "def dollar_bars(data):\n",
    "    data['MarketValue'] = data['price']*data['volume']\n",
    "    data_cm_vol = data.assign(cmVol = data['MarketValue'].cumsum())\n",
    "    total_dol =data_cm_vol.cmVol.values[-1] # data in the last row \n",
    "    dol_per_bar = total_dol/n_time_bars\n",
    "    dol_per_bar = round(dol_per_bar , -2)\n",
    "    data_dol_grp = data_cm_vol.assign(grpId = lambda row:row.cmVol// dol_per_bar)\n",
    "    data_dol_grp = pd.merge(data,data_dol_grp)\n",
    "    data_dol_vwap = data_dol_grp.groupby('grpId').apply(compute_vwap) #grpId\n",
    "    data_dol_vwap.set_index('date_time')\n",
    "    return data\n",
    "    #set the relevant group for each row\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>date_time</th>\n",
       "      <th>price</th>\n",
       "      <th>volume</th>\n",
       "      <th>buy</th>\n",
       "      <th>sell</th>\n",
       "      <th>MarketValue</th>\n",
       "      <th>cmVol</th>\n",
       "      <th>grpId</th>\n",
       "      <th>vwap</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2018-11-21 09:00:00</td>\n",
       "      <td>266.200012</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>266.200012</td>\n",
       "      <td>266.200012</td>\n",
       "      <td>0.0</td>\n",
       "      <td>266.236836</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2018-11-21 09:00:00</td>\n",
       "      <td>266.200012</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>266.200012</td>\n",
       "      <td>532.400024</td>\n",
       "      <td>0.0</td>\n",
       "      <td>266.236836</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2018-11-21 09:00:00</td>\n",
       "      <td>266.200012</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>266.200012</td>\n",
       "      <td>14913.600037</td>\n",
       "      <td>0.0</td>\n",
       "      <td>266.236836</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2018-11-21 09:00:00</td>\n",
       "      <td>266.200012</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>266.200012</td>\n",
       "      <td>15179.800049</td>\n",
       "      <td>0.0</td>\n",
       "      <td>266.236836</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2018-11-21 09:00:00</td>\n",
       "      <td>266.200012</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>266.200012</td>\n",
       "      <td>15446.000061</td>\n",
       "      <td>0.0</td>\n",
       "      <td>266.236836</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            date_time       price  volume  buy  sell  MarketValue  \\\n",
       "0 2018-11-21 09:00:00  266.200012     1.0  0.0   1.0   266.200012   \n",
       "1 2018-11-21 09:00:00  266.200012     1.0  0.0   1.0   266.200012   \n",
       "2 2018-11-21 09:00:00  266.200012     1.0  0.0   1.0   266.200012   \n",
       "3 2018-11-21 09:00:00  266.200012     1.0  0.0   1.0   266.200012   \n",
       "4 2018-11-21 09:00:00  266.200012     1.0  0.0   1.0   266.200012   \n",
       "\n",
       "          cmVol  grpId        vwap  \n",
       "0    266.200012    0.0  266.236836  \n",
       "1    532.400024    0.0  266.236836  \n",
       "2  14913.600037    0.0  266.236836  \n",
       "3  15179.800049    0.0  266.236836  \n",
       "4  15446.000061    0.0  266.236836  "
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data['MarketValue'] = data['price']*data['volume']\n",
    "data_cm_vol = data.assign(cmVol = data['MarketValue'].cumsum())\n",
    "total_dol =data_cm_vol.cmVol.values[-1] # data in the last row \n",
    "dol_per_bar = total_dol/n_time_bars\n",
    "dol_per_bar = round(dol_per_bar , -2)\n",
    "data_dol_grp = data_cm_vol.assign(grpId = lambda row:row.cmVol// dol_per_bar)\n",
    "data_dol_grp = pd.merge(data,data_dol_grp)\n",
    "data_dol_vwap = data_dol_grp.groupby('grpId').apply(compute_vwap) #grpId\n",
    "data_dol_vwap.set_index('date_time')\n",
    "data_dol_vwap.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_drp_d = data_dol_vwap.drop_duplicates(['MarketValue'],keep = 'last')\n",
    "len(data_drp_d) #number of dollar bars\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2.3.2.Information - Driven bars\n",
    "\n",
    "\n",
    "- the purpose of information-driven bars is to sample more frequently when new information arrives to the market.\n",
    "\n",
    "- By synchronizing sampling with the arrival of informed traders, we may be able to make decisions before prices reach a new equilibrium level.We can focus on large moves and ignore less interesting periods.\n",
    "\n"
   ]
  },
  {
   "attachments": {
    "CodeCogsEqn%20%281%29.gif": {
     "image/gif": "R0lGODlhtAAsALMAAP///wAAAJiYmIiIiHZ2dszMzKqqqtzc3DIyMrq6ulRUVCIiIhAQEERERO7u7mZmZiH5BAEAAAAALAAAAAC0ACwAAAT+EMhJq7046817P8rhjWRpnmiqekXDrHAsz3RsKHWu7/z6CL2gcChciIjIpHI0GBgMr6V0Om0AAQocdcvtCRATxbVLLsMYY8bRzG57DoFjIequ2y2FwGTQACTugHcMDgAHCAQAYysOikMChIFKCQRPIAOQMA9LDpoWAgMEBUGfoZEjCQ8LAQ+YA6IVpK8lsRoJAxVOhWA8uYamJA1aE7sUvcRMBrobxwnCejvNE8+/HQGKAo3REtMe2gDcF7kSC69wPOQS5tQcCXEUDWvj5eAc6IX0FQVaCcQCdDX8JvjjYWCAgAeyghBYUOGfn34ONwSUMHBDlAaHCCw8RgOjxo3+Ox4gAuAgSqMcCDpNcOhR4wKOG1qC3PCMgSwGI8dheJClp08FOSnYXBmUYYwvFBYYKPCHh4MAySYcMLryJqICBm9pGCoBZ7o+FxY4eDohD6ZCMshKMEshXtkGcOPK1dpQEYIm0gLo3cu3r9+9FwwEODuVgloAbHdhy3CYrYCFGMTOmcBzx2QJlXPAiQfXbY4HHEtSuAygsrYWGU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AUiGypivMi1RIgZYF00W5AghK4AuhYCYOtWQgEErb54xHFzilcaDhcoikETAFwJSAkURkwAVToLULA8GExjwQMCXA2YAqAJFQXNgDfXZLAXSFYNpx9NlfLtXSVFSC/cBYriSxjXR4jke1qaogDRFhL8jlOAm4pynK6VLXEoOZC/JxQg2u08FGkNBRQ4GDC5Turq+uaJH19nOfgTmJmpX8++fe/z8OPLn08fAMtCfeufEMr8gUv9KHw8h4EC/wG4AV0EvDdEgQZqoJhdYmE0BoENngDaRgxWeIGAA2aoIQWz5VDAWMVM6OGHEwgHnAVs3YZidREAADs="
    }
   },
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2.3.2.1 Tick imbalance bars\n",
    "\n",
    "\n",
    "\n",
    "- Consider a sequence of ticks (p<sub>t</sub>,v<sub>t</sub>)  where they are price and volume respectively. \n",
    "- the tick rule defined a sequence b<sub>t</sub> where\n",
    "![CodeCogsEqn%20%281%29.gif](attachment:CodeCogsEqn%20%281%29.gif)\n",
    "\n",
    "\n",
    "- The idea behind TIB is to sample bars whenever tick imbalances exceed our expectations.\n",
    "\n",
    "- whe should determine the **tick index T** such that the accumulation of signed ticks exceeds a given threshold.\n",
    "![CodeCogsEqn%20%282%29.gif](attachment:CodeCogsEqn%20%282%29.gif)\n",
    "(이 뒤는 VIB/DIB설명과 동일)\n",
    "\n",
    "- TIBs are produced more frequently under the presense of informed trading "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2.3.2.2 Volume/Dollar imbalance bars\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "attachments": {
    "CodeCogsEqn%20%283%29.gif": {
     "image/gif": "R0lGODlh3QAtAMQAAP///wAAAIiIiMzMzNzc3ERERLq6unZ2djIyMu7u7qqqqhAQEGZmZiIiIpiYmFRUVBYWFjg4OAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAADdAC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4hQS1c7ZulAqTp81+oxnNLLYZ0A6xCMDMSkUPAR16Zw5qP1bIeJvyYQ9YZl7HAj7gkM0GUxCepkLCBU23TzTTgzfvwQxu3cMC8K8GA0k5xQULwQQg6lE5EIE0kHUKs5a8NQ0BARCkDPK8wMpEGPoApYQ2/sfDRF66YD7HTSZQQAg4PYrM1M5tSUwE0j5ISmLCZEEhPYDydNdlU6CSPcHzUOBKJM57VtE05xc7waBEH5pTIAaE3sjqX5BmYpbIGRUQ+mQafzyOJfOT6VCVYxwjXIk5fAOFj+/MSwR0BtYzFT4V0fDjJd5jytEGF8IlYsJZH3VULrDL1e2GGtJIDXhgbsxRfrirk22O59vpBsCcXzxVgsXn8r7oTzJOxZcovPiOpoJFR/GoZQJcxf5NJLS71plUmqZQQIsCbta0HTzITXuDjnHHS5YK1tYAdZimn99ntOdF7hiP3tRjTEuQSGkGMCAAYQf1krYHXOJYP/7OQZ5KuN6sISnw7Ox0EnuY9oUpKMBXQwPh+sjwhL0C7ppOcoZYrNCeGTwhBq5gUtHAYfGMCfxIUhejJwECMihLay8esFQuwWEaG1vO7pIIl2WKK0hMCtMnBvijXICxL2hRCG9KtEXCRqwQFKRYX/kIhjYTyBA3xoAxTFwgFa6yIN6qa8ZwCLdDUYmYxyQEcaNHEGN4oGAqr4x0wgwEgU5FnVUFCkjgESVQcYEpEO6UgaLCcIjYoFgfY3ggwGwSEBW5QooSCABbRolKhMpSpXaY8QAAA7"
    }
   },
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![CodeCogsEqn%20%283%29.gif](attachment:CodeCogsEqn%20%283%29.gif)\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "attachments": {
    "CodeCogsEqn%20%282%29.gif": {
     "image/gif": "R0lGODlhaQA2ALMAAP///wAAAJiYmKqqqoiIiO7u7kRERFRUVDIyMmZmZtzc3Lq6uiIiIhAQEMzMzHZ2diH5BAEAAAAALAAAAABpADYAAAT+EMhJq70468kSQQiRNFtpnmiKLotkDBKhznRtA8LUKBJ8/8AgRUESGo82gQHJbJoOMqd0ynFQr81CAMs1EgwBAq9LLpvP6LR6zW673/A4sxEINO74/L3Or/vkQgJ1SyUKAgd1CIBHYGEoBQ8BVotBBXSSKQMJlEIOdQwqDwUXBJNAAgIDAwR/XZEBBz8KYJUvFAQHo2QIfj8LhD8ImxUHsWSWdWM1Dw+nWxYKAS1kC4k3CNM3Bgw5QwsNw2QJdeEqWqqsFwsCw5bKOgeCfdIgZwx12ZkBYw26EwU5GkzCZqHBAQcIEzpQgAAUgA4fQoy4kKCYxYsHmpmIZscfigT+GgE0mOZgVItoE8RIKOnCYcFNLFz4iOJEHjAUDKZpGajsgTEcExCMEXQhGoxuIse0aoJoaQktugY8E0mBwR+kRSQgCDmhWAUiGypivMi1RIgZYF00W5AghK4AuhYCYOtWQgEErb54xHFzilcaDhcoikETAFwJSAkURkwAVToLULA8GExjwQMCXA2YAqAJFQXNgDfXZLAXSFYNpx9NlfLtXSVFSC/cBYriSxjXR4jke1qaogDRFhL8jlOAm4pynK6VLXEoOZC/JxQg2u08FGkNBRQ4GDC5Turq+uaJH19nOfgTmJmpX8++fe/z8OPLn08fAMtCfeufEMr8gUv9KHw8h4EC/wG4AV0EvDdEgQZqoJhdYmE0BoENngDaRgxWeIGAA2aoIQWz5VDAWMVM6OGHEwgHnAVs3YZidREAADs="
    }
   },
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "\n",
    "**step 1)**  \n",
    "\n",
    "get b <sub>t</sub> {-1,1}    \n",
    " Given a sequence of N ticks {p[i], v[i] for i = 1,2...N    \n",
    "  p[i] = price    \n",
    "  v[i] = the number of securities traded(VIB) || the dollar amount exchanged (DIB)    \n",
    "   \n",
    " we first compute change in price from tick to tick, and then define the sequence {b[i]} for i = 1,2....N  \n",
    " \n",
    " Δp[i] := p[i]-p[i-1]  \n",
    " \n",
    " if Δp[i] = 0:  \n",
    "    b[i] := b[i-1]  \n",
    "    \n",
    " else:    \n",
    "    b[i] := abs(Δp[i])/Δp[i]\n",
    "   \n",
    " **step 2)**  \n",
    "\n",
    "compute the imbalance at **time T** defined as  ![CodeCogsEqn%20%282%29.gif](attachment:CodeCogsEqn%20%282%29.gif)\n",
    "\n",
    "p<sub>t</sub> : price   \n",
    "v<sub>t</sub> :  the number of securities traded(VIB) || the dollar amount exchanged (DIB)    \n",
    "   \n",
    "**step 3)**   \n",
    "\n",
    "compute the expected value of T ewma of previous T values.  \n",
    "\n",
    "**step 4)**  \n",
    "\n",
    "compute the expected value of θ<sub>T</sub>(which is E<sub>0</sub>[ θ<sub>T</sub>]) as ewma of b<sub>t</sub>v<sub>t</sub> values.  \n",
    "\n",
    "**step 5)**  \n",
    "\n",
    "for each index:\n",
    " - compute |θ<sub>T</sub>| = E<sub>0</sub>[T] * |2v<sup>+</sup> - E<sub>0</sub>[v<sub>t</sub>]|  \n",
    " - if the condition is met capture the quantitiy of ticks  \n",
    " -reset tick count  \n",
    " -continue  \n",
    "  \n",
    "\n",
    "\n",
    "\n",
    "\n",
    "EWMA: Exponentially Weighted Moving Averages  \n",
    "과거의 모든 데이터를 계산대상으로 하며 최근의 데이터에 더 높은 가중치를 둠."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>date_time</th>\n",
       "      <th>price</th>\n",
       "      <th>volume</th>\n",
       "      <th>buy</th>\n",
       "      <th>sell</th>\n",
       "      <th>CumVol</th>\n",
       "      <th>MarketValue</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2018-11-21 09:00:00</td>\n",
       "      <td>266.200012</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>266.200012</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2018-11-21 09:00:00</td>\n",
       "      <td>266.200012</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>266.200012</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2018-11-21 09:00:00</td>\n",
       "      <td>266.250000</td>\n",
       "      <td>21.0</td>\n",
       "      <td>21.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>23.0</td>\n",
       "      <td>5591.250000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2018-11-21 09:00:00</td>\n",
       "      <td>266.299988</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>24.0</td>\n",
       "      <td>266.299988</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2018-11-21 09:00:00</td>\n",
       "      <td>266.350006</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>26.0</td>\n",
       "      <td>532.700012</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            date_time       price  volume   buy  sell  CumVol  MarketValue\n",
       "0 2018-11-21 09:00:00  266.200012     1.0   0.0   1.0     1.0   266.200012\n",
       "1 2018-11-21 09:00:00  266.200012     1.0   0.0   1.0     2.0   266.200012\n",
       "2 2018-11-21 09:00:00  266.250000    21.0  21.0   0.0    23.0  5591.250000\n",
       "3 2018-11-21 09:00:00  266.299988     1.0   1.0   0.0    24.0   266.299988\n",
       "4 2018-11-21 09:00:00  266.350006     2.0   2.0   0.0    26.0   532.700012"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "#def numba_isclose(a,b,rel_tol = 1e-09, abs_tol = 0.0):\n",
    "  #  return np.fabs(a-b) <= np.fmax(rel_tol*np.fmax(np.fabs(a),np.fabs(b)),abs_tol)\n",
    "\n",
    "def bt(p0, p1,bs): #STEP 1\n",
    "    if math.isclose((p1-p0),0.0,abs_tol = 0.001):\n",
    "        b = bs[-1]\n",
    "        return b\n",
    "    else:\n",
    "        b = np.abs(p1-p0)/(p1-p0)\n",
    "        return b\n",
    "    \n",
    "def get_imbalance(t): # θt (imbalance at time t )\n",
    "    bs = np.zeros_like(t) #크기를 튜플로 명시하지 않고 다른 배열과 같은 크기 배열 사용하고 싶을 떄(그냥 배열 만들기)\n",
    "    for i in tqdm_notebook(np.arange(2,bs.shape[0])):# 리스트를 리턴하는 게 아니라, 행렬을 리턴\n",
    "        t_bt = bt(t[i-1],t[i],bs[:i-1])\n",
    "        bs[i-1] = t_bt\n",
    "    return bs[:-1] #remove last value\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 117,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "1533d75b62b04a6094ccea1504e6a146",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(IntProgress(value=0, max=5256741), HTML(value='')))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "dol_imb = get_imbalance(data.price.values)*data.volume.iloc[1:] #STEP 2\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 241,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1     0.0\n",
       "2    21.0\n",
       "3     1.0\n",
       "4     2.0\n",
       "5    10.0\n",
       "Name: volume, dtype: float64"
      ]
     },
     "execution_count": 241,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dol_imb.head()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 242,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1     0.000000\n",
       "2    10.500999\n",
       "3     7.333397\n",
       "4     5.999667\n",
       "5     6.800038\n",
       "Name: volume, dtype: float64"
      ]
     },
     "execution_count": 242,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "wndo = dol_imb.shape[0]//1000\n",
    "\n",
    "E_bs = dol_imb.ewm(wndo).mean()\n",
    "\n",
    "#E_T is Exponentially Weighted Moving Avg of index values\n",
    "E_T = pd.Series(range(dol_imb.shape[0])).ewm(wndo).mean()\n",
    "\n",
    "#index = dol_imb\n",
    "E_bs.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 122,
   "metadata": {},
   "outputs": [],
   "source": [
    "dol_imb_result = pd.DataFrame().assign(bs = dol_imb).assign(E_T = E_T).assign(E_bs = E_bs).assign(absMul = lambda data: data.E_T*np.abs(data.E_bs)).assign(absTheta = dol_imb.cumsum().abs())\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([<matplotlib.axes._subplots.AxesSubplot object at 0x00000243F7534BA8>,\n",
       "       <matplotlib.axes._subplots.AxesSubplot object at 0x0000024481D55E10>],\n",
       "      dtype=object)"
      ]
     },
     "execution_count": 123,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAuIAAAFdCAYAAABGlwgCAAAABH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uA1p5UppVYBWAUA5VOyHIN1IiIiIhpEL1wDVH+Q2nX6jgTOjJzhTsYvf/lLvPrqqwCAhx9+GLNnz8bjjz+O66+/HllZWSgoKMDrr7+e0vdMtzTxWgDmLCiXAXjWoc06AKeLyARjkObpxjIiIiIiIgBAe3t7WGnKo48+GrW91+vF22+/jauvvhrf//73AQA33HAD1q1bh/feew9r165NeR9dy4iLyCPQme0iEamEngllJYDHRORKAHsBXGi0LQfwLaXU15VSDSJyI4B3jFXdoJSyD/okIiIionSQ4sx1vBItTbn44ouDtz/4wQ8AACeddBIuv/xyXHTRRTj//PNT3kfXAnGl1MURnjrVoe0GAF+3PH4AwAOD1DUiIiIiyjDWqQjN+/feey/eeustPPfcc1iwYAE2b96MwsLClL1nupWmEBERERENObN05dFHH8UJJ5wAANi5cycWLVqEG264AUVFRdi3b1+0VSQs3QZrEhERERENmFkjblqyZEnUKQw7OzuxaNEi9PX14ZFHHgEA/Od//ic++ugjKKVw6qmn4uijj05pHxmIExEREdGI09vbG3fb3bt3AwCuu+66sOVPPfVUKrvUD0tTiIiIiIhcwIw4EREREWWE8847D7t27Qpbdsstt+CMM85wpT8MxImIiIgoIzz99NNudyEMS1OIiIiIKOWUGvkXNR/o78hAnIiIiIhSKjc3F/X19SM6GFdKob6+Hrm5uUmvg6UpRERERJRSJSUlqKysRF1dndtdGVS5ubkoKSlJ+vUMxImIiIgopXJycjBz5ky3u5H2WJpCREREROQCBuJERERERC5gIE5ERERE5AIG4kRERERELmAgTkRERETkAgbiREREREQuYCBOREREROSCtAvERWSeiGy2/DSJyPdtbRaLyCFLm/9xq79ERERERMlIuwv6KKW2AVgAACKSBeATAE87NH1DKXX2UPaNiIiIiChV0i4jbnMqgJ1KqT1ud4SIiIiIKJXSPRBfBuCRCM+dICLvicgLInK4UwMRWS4iG0Rkw+B1kYiIiIgocaKUcrsPjkRkNID9AA5XStXYnvMC6FNKtYjIWQDuUErNiba+8ilZasP+3sHrMBERERERABHZqJQqj9UunTPiZwLY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rIAuBbqjrB1/3icI+402hUdR2wQFWvxE68sVf8BGCPKGcU4CMsFClqzXhuUdX5boSXPc8Cy6NNF6wl8eaROkKtiMyPPCMDgA2q+lcAVf2HL8bljaquiCTJOovIA1haylLMU7atiMyMiq3bA23VWlajqq+5IVbeiEhNdF+/i2lCPwTMBJ7C5n6Gz33loqovAneLyHIRuQbTh78fWAH0EpE5WEqSr/sF4oa40ySiECRY6skQEZkWLbznAGdGqStLsPzAdaUZpbMxiOQlPw3UbfYE4ny/2cAoEfkV1qDjuVKM0dm4qOparOB6IKZ6NBab7/2ioqwfYQaaUyFERjjANlgh/gPY+n4zNt/Tfe4rnu9gc/62qu4M3A2Mw4pzt8XWgpvxdb8gPDXFaTZE5Fiscn6n6PFUYDesYOP0+GTsVBaRR1wxtZz5qvqqWDvrd4GvAG+od8erOEQaNt0QkV8Dl2PRkT2B5/2+r0wiSdotgTHAh1h9yDdU9WMR+SY+9xWNiPRR1XeCx78BfqCqvxWR3YCVvu4XhnfWdJqFKFx5jYjsKSJXY3qi1wGLsjdrp+L4AlO/eRcLTV+BSVfOV9X/LunInI1GghE+FLsOPlZryPLLkgzMaSniPOAFqvp7Efk+Jlt4sar63Fc4WUb4MMyeXBf97NFSjasccY+402yISHssTDkKOE9VryrxkJwWQkR2wCSpngR+qqrXl3hITgsQFWX1xxSRvgL8WFWvLe2onJZAgjb0kZJK79A4cyqbaM67YxGwrYBlqrqstKMqT9wj7jQnJ2A5YXuq6qelHozToqzBagF+4HNfPajqFyLyKfBHYK7PffUQGOF1kXa0G+FVhKpqdO8/Aczxe7/xuEfcaTaCanrHcRzHcRwnD26IO47jOI7jOE4JcPlCx3Ecx3EcxykBbog7juM4juM4TglwQ9xxHMdxHMdxSoAb4o7jOI7jOI5TAtwQdxzHcRzHcZwS4Ia44ziO4ziO45QAN8Qdx3Ecx3EcpwT8HzQxK9/Het3PAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 864x432 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "dol_imb_result[['E_T','E_bs']].plot(subplots = True,figsize = (12,6))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 5256742 entries, 1 to 5256742\n",
      "Data columns (total 5 columns):\n",
      "bs          float64\n",
      "E_T         float64\n",
      "E_bs        float64\n",
      "absMul      float64\n",
      "absTheta    float64\n",
      "dtypes: float64(5)\n",
      "memory usage: 200.5 MB\n"
     ]
    }
   ],
   "source": [
    "dol_imb_result.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>bs</th>\n",
       "      <th>E_T</th>\n",
       "      <th>E_bs</th>\n",
       "      <th>absMul</th>\n",
       "      <th>absTheta</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>5256.742000</td>\n",
       "      <td>5256.741000</td>\n",
       "      <td>5256.742000</td>\n",
       "      <td>5256.741000</td>\n",
       "      <td>5256.742000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>-0.000014</td>\n",
       "      <td>2623.123645</td>\n",
       "      <td>-0.000014</td>\n",
       "      <td>805.436885</td>\n",
       "      <td>50.096279</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>0.013418</td>\n",
       "      <td>1517.475639</td>\n",
       "      <td>0.000383</td>\n",
       "      <td>877.443350</td>\n",
       "      <td>36.587951</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>-0.500000</td>\n",
       "      <td>0.000500</td>\n",
       "      <td>-0.001355</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>-0.002000</td>\n",
       "      <td>1308.930000</td>\n",
       "      <td>-0.000263</td>\n",
       "      <td>170.282265</td>\n",
       "      <td>19.932000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>-0.001000</td>\n",
       "      <td>2623.115000</td>\n",
       "      <td>-0.000018</td>\n",
       "      <td>501.125175</td>\n",
       "      <td>39.127000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>0.002000</td>\n",
       "      <td>3937.300000</td>\n",
       "      <td>0.000233</td>\n",
       "      <td>1113.204655</td>\n",
       "      <td>82.431000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>0.587000</td>\n",
       "      <td>5251.485000</td>\n",
       "      <td>0.010501</td>\n",
       "      <td>7733.317892</td>\n",
       "      <td>125.764000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                bs          E_T         E_bs       absMul     absTheta\n",
       "count  5256.742000  5256.741000  5256.742000  5256.741000  5256.742000\n",
       "mean     -0.000014  2623.123645    -0.000014   805.436885    50.096279\n",
       "std       0.013418  1517.475639     0.000383   877.443350    36.587951\n",
       "min      -0.500000     0.000500    -0.001355     0.000000     0.000000\n",
       "25%      -0.002000  1308.930000    -0.000263   170.282265    19.932000\n",
       "50%      -0.001000  2623.115000    -0.000018   501.125175    39.127000\n",
       "75%       0.002000  3937.300000     0.000233  1113.204655    82.431000\n",
       "max       0.587000  5251.485000     0.010501  7733.317892   125.764000"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display(dol_imb_result.describe()/1000)"
   ]
  },
  {
   "attachments": {
    "CodeCogsEqn%20%284%29.gif": {
     "image/gif": "R0lGODlhTgEVALMAAP///wAAAJiYmBAQEFRUVHZ2du7u7rq6utzc3KqqqszMzDIyMoiIiERERGZmZiIiIiH5BAEAAAAALAAAAABOARUAAAT+EMhJq7046827/2AojmRpnmiqrmzrvnB8Kods33hOGsJUqz/dK2g6JISxoMAg4iGfIgelsaJCKw3CkSMgEKYp4xWr9XS/EyvAIJ0IBoRCYTCQE+qAgoEhHtsSAx8MCmAVAgIJCQxbHWoWCD1NDgMBDpYODQGOFGgAb3FzdQV3BRKdAI4CDJhEHH0sbJSXmJoYpx6njgcMEwRMEngSBz0IDguMfjEGCB8LWBQGDcgMvo0aAgu8Igu3Cm0WndXApcKRuW6/CAHIF2yWDQ2XzCvcFd62IucUzgAIjOpBaABwsIoAoWQIPUVKs+9br1sYNl1IsEAPiHUWtIGT4G8CwAn+AgHoA/DgoMgHH161wFhBYwWIHEZKWAQAmYAAFA4wMWCg1K+EfhrMYyjh5oWPGyRiOBDvp4YDAX6ZZNdLgk2cPn6NHLCwANYOKldAlTqBqql8hUBCJMDvgskVDBZRtMpAAKS60AoIsOTygioGPLroPGTQx96ycQMTIBLomYQGDxZyPDDAYUQQCrwMxVAApQTLF2CyxUcUnOdhbQwM2AwgrIrOE0BvLJd6dei0ExpTGNBXRgNzXwwcUNcjjscHOwO0qiCcuNXIRa04GUCoeYBIc3NbUAPnZoDv3w8saJtB6QYED3pTeFBxkuyXF3iTftwO4/SDC1q5TsG+gPuYEtz+J0F+t5U2wVccBfDWBw544eCDxlmATS891JCAZxUssFBUJBE03iqBWIihABiOIkw/WIk4AQNqoLddbgYpIOOMCCzg2QMeZjMJfSBgYxEGBignDDIK1OUSROosWJWBaWhTgzorsraGC0H+oFKRqnByIpQzzaPATzJJgBwFDCBoA1e5DeUAOTlx2BpKB/wgzUyxsRkhKpL5R8GavWjkomOoYFhBZa3JuYU25vmVDQcJuPnlifwcsiSZZmrJJABxVWBiUSEoAM+noDagnlWO/lJDpAudsqknEywwVJgkOQVPDup4qRsAAyzHQIlSLGRbTbkFkWuAAWxG3W5BFDuBai/+FlUpikf4Os8WiS7LgIYeGPNIAgeg4emkaSQapiIWPMCIZDJoW4E/3Urw7VkTmOuGduBKdCsAAYzKQYMQPsgmSF+x2BqKF6x6DAUI3Etwgm4488OFAy9cE5z04lYROLck3CyQBcz5wQP/foYpGhrDS0G+Gcg0zIoHSiUlDCBbIAU1HOl2iqPMHGAMYCajYsGtCiiowwBM1FhKDxNakIAVN20mgERJe6IGQZhKIEfVnrTFp0ZCAbrGwSs24JTUGz/SwHLnCUlmKasw3DMAQStZL0gOxGnEN26iGwNSK7LdBpcinfzLQpnOTUFmMznwgCYFvOzCAQUkggABPOvF2SL7DNxLuQWWW72QAgXwDLcDS3gOUug/SYpbUXWpYtbmXqNQwAIBgDLK4kzQDLfNKyrO+MtbgfddJwmQrjcMs9cux+0c6q4A72UZP8VbYdIEVAiriim3MptUm0FJZd/AlDBqwKQBrNc/ZcX4b8cHH5Pkpd8Btss+a0MBb3lf3wX6t8APXu3bAPrkh4H/pWoDBnDGAQ20MgJmYHZWIQ+L8uW4GDikf2TKBANYkyhPhQpU+toA6ATwL/OlbHUOxMAIS7gvAZhkJGxIYQYSEDkGhMwPTuBRCjBoAxPOx2cyREsIRlK6IBrxhyfwoQ6yYBYJecFSR/QAE83wRHBRIAIAOw=="
    }
   },
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    " we define VIB of DIB as a T*- contiguous subset of ticks such that the following condition is met:\n",
    "    ![CodeCogsEqn%20%284%29.gif](attachment:CodeCogsEqn%20%284%29.gif)\n",
    "    \n",
    "  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 182,
   "metadata": {},
   "outputs": [],
   "source": [
    "def test_t_abs(absTheta,t,E_bs):\n",
    "    \"\"\"\n",
    "    Bool function to test inequality\n",
    "    *row is assumed to come from df.itertuples()\n",
    "    -absTheta: float(), row.absTheta\n",
    "    -t: pd.Timestamp()\n",
    "    -E_bs: float(), row.E_bs\n",
    "    \"\"\"\n",
    "    return (absTheta >= t*E_bs)\n",
    "\n",
    "def agg_imbalance_bars(df):\n",
    "    \"\"\"\n",
    "    Implements the accumulation logic\n",
    "    \"\"\"\n",
    "    start = df.index[0]  \n",
    "    bars = []\n",
    "    for row in tqdm_notebook(df.itertuples()):\n",
    "      #  print(row)\n",
    "        t_abs = row.absTheta\n",
    "        rowIdx = row.Index\n",
    "        E_bs = row.E_bs\n",
    "        \n",
    "        t = df.loc[start:rowIdx].shape[0]\n",
    "        if t<1: t=1 # if t lt 1 set equal to 1\n",
    "        if test_t_abs(t_abs,t,E_bs):\n",
    "            bars.append((start,rowIdx,t))\n",
    "            start = rowIdx\n",
    "    return bars"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 183,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<map at 0x2451cb5bc50>"
      ]
     },
     "execution_count": 183,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dol_imb_result.itertuples()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 184,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "a89baccfffe74878bbc90e1518a0b2d3",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(IntProgress(value=1, bar_style='info', max=1), HTML(value='')))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#absTheta = dol_imb.cumsum().abs()\n",
    "bars = agg_imbalance_bars(dol_imb_result)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 185,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_imb_bars = (pd.DataFrame(bars,columns=['start','stop','Ts']).drop_duplicates())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 191,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.00240388341955973"
      ]
     },
     "execution_count": 191,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dvlambars = data.price.loc[test_imb_bars.stop].drop_duplicates().pct_change()\n",
    "dvlambars.autocorr()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Exercises\n",
    "\n",
    "\n",
    "all of the following data analysis are performed on KOSPI 200 data.\n",
    "\n",
    "### 2.1.\n",
    "\n",
    "1. Form tick, volume, and dollar bars\n",
    "\n",
    " * as mentioned above\n",
    " \n",
    " \n",
    "2. Count the number of bars produced by tick, volume, and dollar bars on a weekly basis. Plot a time seiries of that bar count. What bar type produces the most stable weekly count? Why?\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 324,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "\n",
    "data_tick_vwap.index = pd.to_datetime(data_tick_vwap.date_time)\n",
    "data_vol_vwap.index = pd.to_datetime(data_vol_vwap.date_time)\n",
    "data_dol_vwap.index = pd.to_datetime(data_dol_vwap.date_time)\n",
    "\n",
    "\n",
    "tick_count = data_tick_vwap['price'].pct_change().resample('1W', label='right').count()\n",
    "\n",
    "\n",
    "volume_count = data_vol_vwap['price'].resample('1W', label='right').count()\n",
    "dollar_count = data_dol_vwap['price'].resample('1W', label='right').count()\n",
    "\n",
    "count_df = pd.concat([ tick_count, volume_count, dollar_count], axis=1)\n",
    "count_df.columns = [ 'tick', 'volume', 'dollar']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_tick_vwap['price'].pct_change().resample('1W', label='right')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 265,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x243774e32e8>"
      ]
     },
     "execution_count": 265,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAmwAAAGgCAYAAAAXVzt3AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAIABJREFUeJzt3XuYXFWZ/v3vAwlEIIYQYjiEmIiMJ4IhwcAMo2SGEaKDICO8ibxj4gEBAQ/z+yHEkUFA4QVkGBQFBiUcPAVkRKIQQkAZUEGSQCBAxCBEiJwix6BEITzvH3t3p9JUd+/qWl319Or7c1376uq1q+5aa+29q1fv2gdzd0REREQkrk3aXQERERER6ZkGbCIiIiLBacAmIiIiEpwGbCIiIiLBacAmIiIiEpwGbCIiIiLBacAmIiIiEpwGbCIiIiLBacAmIiIiEtyQdlcgtW233dbHjx/f7mqIiIiI9Grp0qV/dPfRvT0vuwHb+PHjWbJkSburISIiItIrM/t9lefpK1ERERGR4DRgExEREQlOAzYRERGR4LI7hk1ERERa7+WXX2b16tWsW7eu3VUJadiwYYwdO5ahQ4f26fUasImIiEjTVq9ezfDhwxk/fjxm1u7qhOLuPP3006xevZoJEyb0KUNfiYqIiEjT1q1bx6hRozRYq8PMGDVqVFN7HzVgExERkSQ0WOtes32jAZuIiIhIcDqGTURERJIbP+fapHmrzvjnHuc/99xzfP/73+foo4/mscce4zOf+QxXXXVV9/UrL7S/7bbbJq1nf9EeNhERERnwnnvuOc4//3wAdthhhx4HawORBmwiIiIy4M2ZM4ff/e53TJo0iUMPPZRdd90VgPXr13PccccxceJEdtttN84777yNXvfSSy8xffp0vvWtb7Wj2pXpK1EREZEG1H7Vt2rYYZ2PJ04YB8Dy2ctbXieBM844g3vvvZdly5axatUqDjjgAAAuuugiHn74Ye666y6GDBnCM8880/maF198kZkzZzJr1ixmzZrVrqpXoj1sIiIikq0bb7yRo446iiFDin1U22yzTee8gw46iI997GPhB2ugAZuIiIhkzN27vaTG3nvvzYIFC3D3FteqcRqwiYiIyIA3fPhw1q5d+5ry/fbbjwsvvJBXXnkFYKOvRE899VRGjRrF0Ucf3bJ69pWOYRMREZHkersMR2qjRo1i7733Ztddd+Vtb3tbZ/nhhx/Ob3/7W3bbbTeGDh3KJz/5SY499tjO+eeeey4f//jHOf744znrrLNaWudGaMAmIiIiWfj+97//mrIhQ4ZwzjnncM4552xUvmrVqs7Hl1xySX9XrWn6SlREREQkOA3YRERERILTgE1EREQkOA3YRERERILTgE1EREQkOA3YRERERILTZT1EREQkvZNHJM57PllUx71G77333mSZ/U172ERERESC0x42kTYbP+fazserhh3W+XjihHGdj5fPXt7SOolIfPU+Owbz58YJJ5zAG9/4xs7bTJ188skMHz6cJ554ggULFmBmnHjiicyYMWOj11166aUsWbKEb3zjGwAccMABHHfccUybNo2tttqKY445hhtvvJGRI0dy+umnc/zxx/PII49w7rnncuCBB7J+/XrmzJnDzTffzF/+8heOOeYYjjzyyOTt0x42ERERGfBmzpzJFVdc0fn7lVdeybbbbsuyZcu4++67ufHGG/n85z/P448/XjnzT3/6E9OmTWPp0qUMHz6cE088kUWLFnH11Vdz0kknAXDxxRczYsQIFi9ezOLFi/nWt77Fww8/nLx92sMmIiIiA97uu+/OU089xWOPPcaaNWsYOXIky5Yt48Mf/jCbbropY8aMYZ999mHx4sXstttulTI322wzpk+fDsDEiRPZfPPNGTp0KBMnTuy8tdUNN9zAPffcw1VXXQXA888/z8qVK5kwYULS9mnAJiIiIlk45JBDuOqqq3jiiSeYOXMmv/vd73p9zZAhQ3j11Vc7f1+3bl3n46FDh2JmAGyyySZsvvnmnY9feeUVANyd8847j/333z9lU15DX4mKiIhIFmbOnMm8efO46qqrOOSQQ3jPe97DFVdcwfr161mzZg233HILU6dO3eg148ePZ9myZbz66qs8+uij3HHHHQ295/77788FF1zAyy+/DMBvf/tb/vSnPyVrUwftYRMREZH0El6Go6p3vOMdrF27lh133JHtt9+egw8+mNtuu413vvOdmBlnnXUW2223XefXmQB77703EyZMYOLEiey6665Mnjy5ofc8/PDDWbVqFZMnT8bdGT16ND/+8Y8Tt0wDNhEREcnI8uUbzo41M7761a/y1a9+daPnjB8/vvMabGbG9773vbpZL774Yufjk08+ue68TTbZhNNPP53TTz89RfW7pa9ERURERILTgE1EREQkOA3YRERERILTgE1EREQkOA3YRERERILTgE1EREQkOF3WQ0RERJKbeNnEpHl9uZn9ySefzFZbbcVxxx1Xd/5HP/pRDjjgAA455BCmTZvG2WefzR577NFsVfuF9rCJiIiINGj9+vUtfT/tYZMBa/ycawFYNeywzrKJE8Z1Pu7Lf2MiIjKwnXbaaVx++eXstNNOjB49milTprBs2TKOOuoo/vznP7Pzzjszd+5cRo4c2W3Gpz71KRYvXsxLL73EIYccwimnnAIUF9z9+Mc/zg033MCxxx7LzJkzW9UsDdhERERareMfTqj/T6f+4eybpUuXMm/ePO666y5eeeUVJk+ezJQpU5g1axbnnXce++yzDyeddBKnnHIK5557brc5p512Gttssw3r169n33335Z577mG33XYDYNiwYfziF79oVZM66StRERERycKtt97KwQcfzBZbbMHrX/96DjzwQP70pz/x3HPPsc8++wAwe/Zsbrnllh5zrrzySiZPnszuu+/Offfdx/333985b8aMGf3ahu5oD5uIiIhkw8yaev3DDz/M2WefzeLFixk5ciQf/ehHWbduXef8Lbfcstkq9kmve9jMbCcz+7mZrTCz+8zss2X5Nma2yMxWlj9HluVmZl83swfN7B4zm1yTNbt8/kozm11TPsXMlpev+bqVvd3de4iIiIh09Z73vIerr76al156ibVr1/KTn/yELbfckpEjR3LrrbcC8J3vfKdzb1s9L7zwAltuuSUjRozgySefZMGCBa2qfo+q7GF7Bfi/7n6nmQ0HlprZIuCjwE3ufoaZzQHmACcA7wN2Kac9gQuAPc1sG+BLwB6Alznz3f3Z8jlHALcD1wHTgQVlZr33EBERkcDacRze5MmTmTFjBpMmTeKNb3wj7373uwG47LLLOk86eNOb3sQll1zSbcY73/lOdt99d97xjnfwpje9ib333rtV1e9RrwM2d38ceLx8vNbMVgA7AgcB08qnXQbcTDGYOgi43N0duN3Mtjaz7cvnLnL3ZwDKQd90M7sZeL2731aWXw58kGLA1t17iIiIiLzGF7/4Rb74xS++pvz2229/Tdmll17a+fjmm2+uW15r1apVTdau7xo66cDMxgO7A78GxpSDuY5B3RvKp+0IPFrzstVlWU/lq+uU08N7iIiIiAwalQdsZrYV8D/A59z9hZ6eWqfM+1BemZkdYWZLzGzJmjVrGnmpiIiISHiVBmxmNpRisPY9d/9RWfxk+VUn5c+nyvLVwE41Lx8LPNZL+dg65T29x0bc/SJ338Pd9xg9enSVJomIiEhixdFQUk+zfVPlLFEDLgZWuPs5NbPmAx1nes4Grqkpn1WeLboX8Hz5deZCYD8zG1me7bkfsLCct9bM9irfa1aXrHrvISIiIoEMGzaMp59+WoO2Otydp59+mmHDhvU5o8pZonsDHwGWm9mysuzfgTOAK83sE8AjwKHlvOuA9wMPAn8GPlZW9hkz+zKwuHzeqR0nIACfAi4FXkdxskHHObTdvYeIiIg0qd4dF/p6i7+xY8eyevVqdGhSfcOGDWPs2LG9P7EbVc4S/QX1jzMD2LfO8x04ppusucDcOuVLgF3rlD9d7z1EREQklqFDhzJhwoR2VyNbujWViIiISHAasImIiIgEp3uJighQ/1gW6PvxLCIiko72sImIiIgEpwGbiIiISHAasImIiIgEpwGbiIiISHA66UCkCTpQP6aUFwMVEYlAe9hEREREgtOATURERCQ4DdhEREREgtOATURERCQ4DdhEREREgtOATURERCQ4DdhEREREgtOATURERCQ4XTi3RXq7wKou5CkiIiLd0R42ERERkeA0YBMREREJTgM2ERERkeA0YBMREREJTgM2ERERkeA0YBMREREJTpf1EJFkdPkaEZH+oT1sIiIiIsFpwCYiIiISnAZsIiIiIsFpwCYiIiISnAZsIiIiIsFpwCYiIiISnAZsIiIiIsFpwCYiIiISnAZsIiIiIsHpTgcDiK4in1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yp4F965Q7cEw3WXOBuXXKlwC79rWOIiIiIjnQnQ5EREREgtOATURERCQ4DdhEREREgtOATURERCQ4DdhEREREgtOATURERCQ4DdhEREREgtOATURERCQ4DdhEREREgtOATURERCQ4DdhEREREgtOATURERCQ4DdhEREREgtOATURERCQ4DdhEREREgtOATURERCQ4DdhEREREgtOATURERCQ4DdhEREREgtOATURERCQ4DdhEREREgtOATURERCQ4DdhEREREgtOATURERCQ4DdhEREREgtOATURERCQ4DdhEREREgtOATURERCQ4DdhEREREgtOATURERCQ4DdhEREREgtOATURERCQ4DdhEREREgtOATURERCQ4DdhEREREgtOATURERCQ4DdhEREREgtOATURERCQ4DdhEREREgtOATURERCQ4DdhEREREgtOATURERCQ4DdhEREREgtOATURERCQ4DdhEREREgtOATURERCS48AM2M5tuZg+Y2YNmNqfd9RERERFptdADNjPbFPgm8D7g7cCHzezt7a2ViIiISGuFHrABU4EH3f0hd/8rMA84qM11EhEREWmp6AO2HYFHa35fXZaJiIiIDBrm7u2uQ7fM7FBgf3c/vPz9I8BUd/90l+cdARxR/voW4IEeYrcF/thk1ZShjP7MiFAHZSijvzMi1EEZyujvjCqvf6O7j+41yd3DTsDfAgtrfv8C8IUmM5ckqJcylNFvGRHqoAxl9HdGhDooQxn9nZGiDh1T9K9EFwO7mNkEM9sMmAnMb3OdRERERFpqSLsr0BN3f8XMjgUWApsCc939vjZXS0RERKSlQg/YANz9OuC6hJEXKUMZwTMi1EEZyujvjAh1UIYy+jsjRR2A4CcdiIiIiEj8y3qIiIiIDHoasImIiIgEF/4YtnYzM6O448KOgAOPAXd4A98lp8hIIVU9zGxMbYa7P9nqekTJSCFCf6aQsh5mtg3g7v5sH+sSok+brUcuGVH6M8q2EkVmn6NtX8f6uy+yPobNzEYA09m48xa6+3MVX78fcD6wEvhDWTwWeDNwtLvf0IqMQG2ZBFwIjOiS8VyZcWeL6hEio8zp83KJ0p/NtiNVPcxsHHAWsC9FHxjweuBnwBx3X1UhI0SfJqpHFhmB+jPEth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TkSuQmCC\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "count_df.plot(kind='bar', figsize = [10,5])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 317,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "38806.515247144955"
      ]
     },
     "execution_count": 317,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "tick_count.std()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 287,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "38806.515247144955"
      ]
     },
     "execution_count": 287,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "volume_count.std()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 288,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "38806.515247144955"
      ]
     },
     "execution_count": 288,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# We cannot figure out what bar type produces the most stable weekly count..?\n",
    "tick_count.std()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3.Compute serieal correlation of returns for the three bar types. What bar method has the lowest serial correlation?\n",
    "\n",
    "* serial correlation(autocorrelation) : correlation between serial returns\n",
    "(시간 또는 공간적으로 연속된 일련의 관측치들간에 존재하는 상관관계)\n",
    "회귀분석에서 시계열의 관측값이 선행된 관측값에 의존하여 자기상관을 보일 때, 즉 관측값이 선행관측값들의 회귀관계를 갖는 현상을 autocorrelation이라고 한다.\n",
    "일반적으로 자기회귀현상은 회귀계수의 효율성을 보장 못하기에 회귀분석은 자기회귀가 존재하지 않는다는 것이 전제되어야 한다(왜곡 방지)\n",
    "\n",
    "* acf : autocorrelation function in python\n",
    "https://datascienceschool.net/view-notebook/12c6c314797c4c438d06e5cf4d290840/\n",
    "\n",
    "- 10T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-0.0069020611673073695"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#data_tick_vwap.set_index('index')\n",
    "data_drp = data_tick_vwap.set_index('index').drop_duplicates(['grpId'],keep = 'last')\n",
    "data_drp['price'].pct_change().autocorr()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 212,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-0.005350698642231118"
      ]
     },
     "execution_count": 212,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_drp_v = data_vol_vwap.drop_duplicates(['grpId'],keep = 'last')\n",
    "data_drp_v['price'].pct_change().autocorr()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 252,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-0.00040415886705216455"
      ]
     },
     "execution_count": 252,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_drp_d = data_dol_vwap.drop_duplicates(['grpId'],keep = 'last')\n",
    "data_drp_d['price'].pct_change().autocorr()\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4. Partition the bar series into monthly subsets. compute the variance of returns for every subset of every bar type. Compute the variance of those variances. What method exhibits the smallest variances of variances?\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 257,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Partition the bar series into monthly subsets.compute the variance of returns for every subset of every bar type.\n",
    "tick_month = pd.DataFrame(data_drp).set_index('date_time').resample('M',label = 'left')\n",
    "tick_m_pct = tick_month['price'].ohlc().pct_change()\n",
    "#Compute the variance of those variances. \n",
    "tick_m_ret = tick_m_pct['close'].var()\n",
    "\n",
    "\n",
    "vol_month = pd.DataFrame(data_drp_v).set_index('date_time').resample('W',label = 'left')\n",
    "vol_m_pct = vol_month['price'].ohlc().pct_change()\n",
    "vol_m_ret = vol_m_pct['close'].var()\n",
    "\n",
    "dol_month = pd.DataFrame(data_drp_d).set_index('date_time').resample('W',label = 'left')\n",
    "dol_m_pct = dol_month['price'].ohlc().pct_change()\n",
    "dol_m_ret = dol_m_pct['close'].var()\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 258,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0.002938334556020005, 0.0003864459715377553, 0.00038908098321886427]"
      ]
     },
     "execution_count": 258,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Compute the variance of those variances. \n",
    "ret = [tick_m_ret, vol_m_ret, dol_m_ret]\n",
    "ret"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "dollar bars exhibits the smallest var of vars."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "5. Apply the Jarque-Bera normality test on returns from the three bar types. What bar type achieves the lowest test statistic?\n",
    "\n",
    " * the Jarque-Bera test tests whether the sample data has the skewness and kurtosis matching a normal distribution.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(0.7415727430999782, 0.6901913703233922)"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 1 week\n",
    "tick_ohlc = tick_month['price'].ohlc()\n",
    "tick_ret = np.log(tick_ohlc['close']).diff().dropna()\n",
    "stats.jarque_bera(tick_ohlc['close'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(0.2495552838163049, 0.8826931547302332)"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stats.jarque_bera(vol_m_pct['close'].dropna())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 259,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(0.6649107372073904, 0.7171606760320643)"
      ]
     },
     "execution_count": 259,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stats.jarque_bera(dol_m_pct['close'].dropna())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "module 'seaborn' has no attribute 'displot'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-14-c434d7d2a35a>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0msns\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdisplot\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mstats\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mjarque_bera\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtick_ohlc\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'close'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mAttributeError\u001b[0m: module 'seaborn' has no attribute 'displot'"
     ]
    }
   ],
   "source": [
    "sns.displot(stats.jarque_bera(tick_ohlc['close'])[0])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "volume bars achieves the lowest statistic.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.2\n",
    "\n",
    "compute dollar bars and dollar imbalance bars. What bar type exhibits greater serial correlation?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 253,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-0.00040415886705216455"
      ]
     },
     "execution_count": 253,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_drp_d['price'].pct_change().autocorr() # dollar bars"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 239,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.00240388341955973"
      ]
     },
     "execution_count": 239,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dvlambars.autocorr() #dollar imbalance bars"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## CUSUM Filter\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1205"
      ]
     },
     "execution_count": 105,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import itertools as it \n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "from datetime import datetime\n",
    "import time\n",
    "\n",
    "\n",
    "#10T\n",
    "h=0.005\n",
    "tmp = np.log(data_time_group.price.close).diff().dropna()\n",
    "# if (x+y)< h이면 max(x+y,0)를 구하는 거고 else이면 0\n",
    "# 즉 (x+y)>=h일때 0\n",
    "#근데 책에도 보면 S>= h일 때 event가 발생하는 거니까 여기서 0은 이벤트가 발생했으면 0으로 놓는다는 것\n",
    "tmp_p = list(it.accumulate(tmp, lambda x, y: max(x+y, 0) if (x+y) < h else 0))\n",
    "tmp_n = list(it.accumulate(tmp, lambda x, y: min(x+y, 0) if (x+y) < -h else 0))\n",
    "# (x+y) => h일떄  sq로 집어넣는거\n",
    "s1 = [index for index, value in enumerate(tmp_p) if value ==0]\n",
    "s2 = [index for index, value in enumerate(tmp_n) if value ==0]\n",
    "#print(set(s1) & set(s2))\n",
    "\n",
    "n = (set(s1) & set(s2))\n",
    "len(n)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "289"
      ]
     },
     "execution_count": 110,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "threshold=0.005\n",
    "t_events = []\n",
    "s_pos = 0\n",
    "s_neg = 0\n",
    "\n",
    "    # log returns\n",
    "diff = np.log(data_time_group.price.close).diff().fillna(0)\n",
    "    # Get event time stamps for the entire series\n",
    "for i in diff.index[1:]:\n",
    "    pos = float(s_pos + diff.loc[i])\n",
    "    neg = float(s_neg + diff.loc[i])\n",
    "    s_pos = max(0.0, pos)\n",
    "    s_neg = min(0.0, neg)\n",
    "\n",
    "    if s_neg < -threshold:\n",
    "        s_neg = 0\n",
    "        t_events.append(i)\n",
    "\n",
    "    elif s_pos > threshold:\n",
    "        s_pos = 0\n",
    "        t_events.append(i)\n",
    "\n",
    "    # Return DatetimeIndex or list\n",
    "\n",
    "event_timestamps = pd.DatetimeIndex(t_events)\n",
    "    #return event_timestamps\n",
    "\n",
    "len(event_timestamps)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "date_time\n",
       "2018-11-21 09:10:00    0.000000\n",
       "2018-11-21 09:20:00   -0.001127\n",
       "2018-11-21 09:30:00   -0.000564\n",
       "2018-11-21 09:40:00   -0.000752\n",
       "2018-11-21 09:50:00    0.000564\n",
       "2018-11-21 10:00:00   -0.001129\n",
       "2018-11-21 10:10:00    0.001505\n",
       "2018-11-21 10:20:00    0.001315\n",
       "2018-11-21 10:30:00    0.002438\n",
       "2018-11-21 10:40:00   -0.000187\n",
       "2018-11-21 10:50:00    0.000187\n",
       "2018-11-21 11:00:00    0.001871\n",
       "2018-11-21 11:10:00   -0.000374\n",
       "2018-11-21 11:20:00   -0.000374\n",
       "2018-11-21 11:30:00   -0.000374\n",
       "2018-11-21 11:40:00    0.000374\n",
       "2018-11-21 11:50:00    0.000935\n",
       "2018-11-21 12:00:00    0.001121\n",
       "2018-11-21 12:10:00    0.000933\n",
       "2018-11-21 12:20:00    0.000560\n",
       "2018-11-21 12:30:00   -0.000560\n",
       "2018-11-21 12:40:00    0.000000\n",
       "2018-11-21 12:50:00   -0.000187\n",
       "2018-11-21 13:00:00    0.000932\n",
       "2018-11-21 13:10:00   -0.000373\n",
       "2018-11-21 13:20:00    0.000746\n",
       "2018-11-21 13:30:00   -0.000186\n",
       "2018-11-21 13:40:00    0.000559\n",
       "2018-11-21 13:50:00    0.000186\n",
       "2018-11-21 14:00:00   -0.001304\n",
       "                         ...   \n",
       "2019-07-02 10:40:00    0.000000\n",
       "2019-07-02 10:50:00   -0.001440\n",
       "2019-07-02 11:00:00   -0.001803\n",
       "2019-07-02 11:10:00    0.000902\n",
       "2019-07-02 11:20:00    0.000180\n",
       "2019-07-02 11:30:00   -0.000541\n",
       "2019-07-02 11:40:00    0.000721\n",
       "2019-07-02 11:50:00   -0.000541\n",
       "2019-07-02 12:00:00   -0.000541\n",
       "2019-07-02 12:10:00    0.000000\n",
       "2019-07-02 12:20:00    0.000721\n",
       "2019-07-02 12:30:00   -0.000361\n",
       "2019-07-02 12:40:00    0.000000\n",
       "2019-07-02 12:50:00   -0.000361\n",
       "2019-07-02 13:00:00    0.000541\n",
       "2019-07-02 13:10:00   -0.000541\n",
       "2019-07-02 13:20:00   -0.000722\n",
       "2019-07-02 13:30:00    0.000361\n",
       "2019-07-02 13:40:00    0.000541\n",
       "2019-07-02 13:50:00   -0.000180\n",
       "2019-07-02 14:00:00   -0.000181\n",
       "2019-07-02 14:10:00   -0.000722\n",
       "2019-07-02 14:20:00    0.000000\n",
       "2019-07-02 14:30:00    0.000542\n",
       "2019-07-02 14:40:00    0.000000\n",
       "2019-07-02 14:50:00   -0.000542\n",
       "2019-07-02 15:00:00    0.000722\n",
       "2019-07-02 15:10:00    0.000000\n",
       "2019-07-02 15:20:00   -0.001264\n",
       "2019-07-02 15:30:00    0.000542\n",
       "Name: close, Length: 5844, dtype: float64"
      ]
     },
     "execution_count": 109,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "diff.dropna()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def npMovingAverage(data, window=3):\n",
    "    weights = np.ones(window) / window\n",
    "    return np.convolve(data, weights, mode='valid')\n",
    "\n",
    "def getDailityVol (\n",
    "    df,\n",
    "    col_close='close',\n",
    "    col_dVol='dVol',\n",
    "    span0 = 100\n",
    "    ):\n",
    "    df[col_dVol]=df[col_close].pct_change()\n",
    "    df[col_dVol] = df[col_dVol].ewm(span=100).std()\n",
    "    return df[col_dVol]\n",
    "\n",
    "def CUSUM_dVol(\n",
    "    df,\n",
    "    col='close',\n",
    "    window=20,\n",
    "    h=0.05\n",
    "   ):\n",
    "    bar = df.drop(df.columns.difference([col]), axis=1)\n",
    "    tmp = np.log(bar[col]).diff().fillna(0)\n",
    "        \n",
    "    ma = npMovingAverage(tmp,window)      \n",
    "    tmp = tmp[window-1:]\n",
    "    tmp = tmp - ma    \n",
    "    \n",
    "    dVol = getDailityVol(df,col_close='price')\n",
    "    tmp_p = tmp - dVol\n",
    "    tmp_n = tmp + dVol \n",
    "    \n",
    "    tmp_p = list(it.accumulate(tmp_p, lambda x, y: max(x+y, 0) if (x+y) >= 0 else 0))\n",
    "    tmp_n = list(it.accumulate(tmp_n, lambda x, y: min(x+y, 0) if (x+y) <= 0 else 0))\n",
    "    \n",
    "    s1 = [index for index, value in enumerate(tmp_p) if value !=0]\n",
    "    s2 = [index for index, value in enumerate(tmp_n) if value !=0]\n",
    "        \n",
    "    s_p = bar.iloc[s1]\n",
    "    s_n = bar.iloc[s2]    \n",
    "    \n",
    "    s_t = pd.concat([s_p,s_n],axis = 1,sort=True)\n",
    "    s_t.columns = ['s_p','s_n']\n",
    "    \n",
    "    #s_t['s_t'] = s_t.apply(lambda x: x['s_n'] if pd.isna(x['s_p']) else x['s_p'],axis=1)\n",
    "    \n",
    "    return s_t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
